package com.itheima.tlias.controller;

import com.itheima.tlias.anno.Log;
import com.itheima.tlias.pojo.Dept;
import com.itheima.tlias.pojo.Result;
import com.itheima.tlias.servies.DeptServices;
import com.itheima.tlias.servies.EmpServices;
import com.sun.net.httpserver.Authenticator;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class DeptController {

    @Autowired
    private DeptServices deptServices;



    @GetMapping("/depts")
    public Result query(){
        List<Dept> deptList = deptServices.list();

        log.info("查询部门数据");
        return Result.success(deptList);
    }
    @Log
    @DeleteMapping("/depts/{id}")
    public Result DeleteByid(@PathVariable Integer id) {
        deptServices.DeleteById(id);
        log.info("根据ID删除部门{}",id);
        return Result.success();
    }

    @Log
    @PostMapping("/depts")
    public Result Add(@RequestBody Dept dept){
        deptServices.add(dept);
        log.info("添加部门{}",dept.getName());
        return Result.success();
    }
    @GetMapping("/depts/{id}")
    public Result SelectD(@PathVariable Integer id){
        Dept dept = deptServices.select(id);
        log.info("查询部门名称{}",id);
        return Result.success(dept);
    }
    @Log
    @PutMapping("/depts")
    public Result Updata(@RequestBody Dept dept){
        deptServices.update(dept);
        log.info("正在修改部门数据{}",dept.getName());
        return Result.success();
    }

}
